<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="108px">

      <el-form-item label="店铺" prop="shopsName">
        <el-input
          v-model="queryParams.shopsName"
          placeholder="请输入店铺名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

      <el-form-item label="类型" prop="constructionType">
        <el-select v-model="queryParams.constructionType" placeholder="请选择" clearable size="small">
          <el-option label="建房施工" value="0"/>
          <el-option label="装修施工" value="1"/>
          <el-option label="同城安装" value="6"/>
        </el-select>
      </el-form-item>


      <el-form-item label="地址" prop="address">
        <el-input
          v-model="queryParams.address"
          placeholder="请输入地址"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="0建房 1装修  6同城安装" prop="constructionType">-->
<!--        <el-select v-model="queryParams.constructionType" placeholder="请选择0建房 1装修  6同城安装" clearable size="small">-->
<!--          <el-option label="请选择字典生成" value="" />-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="施工队ID" align="center" prop="constructionId" />
<!--      <el-table-column label="施工队编码" align="center" prop="constructionCore" />-->
      <el-table-column label="姓名" align="center" prop="constructionName" />
      <el-table-column label="顺序" align="center" prop="oneTeamId" />
<!--      <el-table-column label="商品/施工队的供应商ID" align="center" prop="supplierId" />-->
<!--      <el-table-column label="施工队的分类ID" align="center" prop="teamId" />-->
      <el-table-column label="施工队销售价格" align="center" prop="price" />
      <el-table-column label="地区" align="center" prop="address" />
      <el-table-column label="店铺名称" align="center" prop="shopsName" />

      <el-table-column label="队伍人数" align="center" prop="teamNumber" />
<!--      <el-table-column label="0建房 1装修  6同城安装" align="center" prop="constructionType" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >修改</el-button>

        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改供应商信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="序号" prop="oneTeamId">
          <el-input v-model="form.oneTeamId" placeholder="序号" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { shigongEdit,shigongList,getshigongId } from "../../../api/sequence";

  export default {
        name: "index",
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 供应商信息表格数据
        infoList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          constructionCore: null,
          constructionName: null,
          oneTeamId: null,
          twoTeamId: null,
          threeTeamId: null,
          supplierId: null,
          teamId: null,
          price: null,
          publishStatus: null,
          auditStatus: null,
          constructionDate: null,
          descript: null,
          modifiedTime: null,
          teamNumber: null,
          constructionType: null
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          constructionCore: [
            { required: true, message: "施工队编码不能为空", trigger: "blur" }
          ],
          constructionName: [
            { required: true, message: "姓名不能为空", trigger: "blur" }
          ],
          supplierId: [
            { required: true, message: "商品/施工队的供应商ID不能为空", trigger: "blur" }
          ],
          teamId: [
            { required: true, message: "施工队的分类ID不能为空", trigger: "blur" }
          ],
          price: [
            { required: true, message: "施工队销售价格不能为空", trigger: "blur" }
          ],
          publishStatus: [
            { required: true, message: "上下架状态：0上架1下架不能为空", trigger: "blur" }
          ],
          auditStatus: [
            { required: true, message: "审核状态：0未审核，1已审核不能为空", trigger: "blur" }
          ],
          constructionDate: [
            { required: true, message: "施工队录入时间不能为空", trigger: "blur" }
          ],
          descript: [
            { required: true, message: "施工队描述不能为空", trigger: "blur" }
          ],
          modifiedTime: [
            { required: true, message: "最后修改时间不能为空", trigger: "blur" }
          ],
          delFlag: [
            { required: true, message: "删除的标识不能为空", trigger: "blur" }
          ],
        }
      };
    },
    created() {
      this.getList();
    },

    methods: {
      /** 查询供应商信息列表 */
      getList() {
        this.loading = true;
        shigongList(this.queryParams).then(response => {
          this.infoList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          constructionId: null,
          constructionCore: null,
          constructionName: null,
          oneTeamId: null,
          twoTeamId: null,
          threeTeamId: null,
          supplierId: null,
          teamId: null,
          price: null,
          publishStatus: 0,
          auditStatus: 0,
          constructionDate: null,
          descript: null,
          modifiedTime: null,
          delFlag: null,
          teamNumber: null,
          constructionType: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.constructionId)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },

      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const constructionId = row.constructionId || this.ids
        getshigongId(constructionId).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改供应商信息";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.constructionId != null) {
              shigongEdit(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                }
              });
            } else {
              addInfo(this.form).then(response => {
                if (response.code === 200) {
                  this.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                }
              });
            }
          }
        });
      },


    }

    }
</script>

<style scoped>

</style>
